package com.hut.oa.model.dao.task;

import java.util.Date;
import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.hut.oa.model.bean.AddressBook;
import com.hut.oa.model.bean.TaskManage;
import com.hut.oa.model.bean.TaskUser;
import com.hut.oa.model.bean.User;

public interface TaskDao extends PagingAndSortingRepository<TaskManage, Long>{
		
	Page<TaskManage> findByUser(Pageable pageable,User u);
	
	List<TaskManage> findByUser(User u);
	
	TaskManage findByUserAndTmId(User u,Long tmid);
	
	@Query("update TaskManage task set task.tmStatus=:status  where task.tmId=:taskid")
	@Modifying
	int updatestatus(@Param("status")Long status,@Param("taskid")Long taskid);
	
	@Query("from TaskManage task where task.tmTitle like CONCAT('%',:tittle,'%') and task.user=:u")
	Page<TaskManage> findbytittle(Pageable pageable,@Param("tittle")String tittle,@Param("u")User u);
	
	@Query("from TaskManage task where task.tmEndTime<=:date and task.user=:u and task.tmStatus<>4 and task.tmStatus<>5)")
	List<TaskManage> findbytime(@Param("date")Date date,@Param("u")User u);
	
	Page<TaskManage> findByTmStatusAndUser(Pageable pageable,Long status,User u);
}
